<admintpl file="header" />
</head>
<style>
.question{padding-left: 3px;cursor: pointer}
</style>
<body style="min-width: 800px;">
<php>$leave_en = C('VACATION_TYPE_EN');
	$leave_ch = C('VACATION_TYPE');
	$leave_evection = C('LEAVE_TYPE');
    $ot = C('OT_TYPE');
    $leave_evection[] = $ot[0];
    $leave_evection[] = $ot[1];
	foreach($leave_evection as $k=>$v){
		$leave_en[] = $v['label'];
		$leave_ch[] = $v['title'];
	}
</php>
	<div class="wrap js-check-wrap">
		<ul class="nav nav-tabs">
			<li class="active"><a href="">月度考勤数据</a></li>
			<li class=""><a class="" href="{:U('print_monthly',['print'=>2,'map'=>$map])}" target='_blank'>导出预览</a></li>
			<li class=""><a class="loadingurl" href="{:U('print_monthly',['print'=>1,'map'=>$map])}" target='_blank'>导出(分部门)</a></li>
			<li class=""><a class="loadingurl" href="{:U('print_monthly_no_dep',['print'=>1,'map'=>$map])}" target='_blank'>导出(不分部门)</a></li>
		</ul>
		<form class="well form-search" method="post" action="{:U('monthly')}">
			考勤周期
			<input type="text" name="start_date" class="js-date" id='date_s' value="{$_REQUEST[start_date]? $_REQUEST[start_date]:$start_mon}" style="width: 80px;" autocomplete="off">-
			<input autocomplete="off" type="text" class="js-date" id='date_e' name="end_date" value="{$_REQUEST['end_date'] ? $_REQUEST[end_date]: $end_mon}" style="width: 80px;"> 姓名
			<input type="text" name="name" style="width: 80px;" id='name' value="{$_REQUEST[name]}"> 部门 
			<select name="dep_id" id="dep_id">
				<option value="">全部</option>
				{$department}
			</select>
			<button class="btn btn-primary">搜索</button>
			<a class="btn btn-primary" href="{:U('')}">清空</a>
		</form>
		<form class="js-ajax-form" method="post">

			<table class="table table-hover table-bordered table-list">
				<thead>
					<tr>
						<th width="">工号</th>
						<th width="">姓名</th>
						<th width="">部门</th>
						<th width="">应出勤天数 <a href="{:U('showrule',['n'=>2])}" class='js-dialog fa fa-question-circle question' data-width='700px' title='实际工时说明'></a></th>
						<th width="">加班小时</th>
						<th width="">迟到小时</th>
						<th width="">早退小时</th>
						<th width="">有效工时 <a href="{:U('showrule',['n'=>1])}" class='js-dialog fa fa-question-circle question' data-width='700px' title='实际工时说明'></a></th>
						<th width="">实际工时</th>
						<th width="">准时在岗</th>
						<th width="">准时在岗率<a href="{:U('showrule',['n'=>4])}" class='js-dialog fa fa-question-circle question' data-width='700px' title='实际工时说明'></a></th>
						<th width="">缺时时数  <a href="{:U('showrule',['n'=>3])}" class='js-dialog fa fa-question-circle question' data-width='700px' title='实际工时说明'></a></th>
						<th width="">可补休小时<i class='fa fa-question-circle question'></i></th>
						<th width="">请假小时</th>
					</tr>
				</thead>
				<foreach name="list" item="vo">
				<tr>
					<td>{$vo.sn}</td>
					<td>{$vo.name}</td>
					<td>{$vo.dep_name}</td>
					<td>{$vo.work_day}</td>
					<td>{$vo.overtime|get_hour = ###}</td>
					<td>{$vo.stu_late|get_hour = ###}</td>
					<td>{$vo.stu_leave_early|get_hour = ###}</td>
					<td>{$vo.work_effect|get_hour = ###}</td>
					<td>{$vo.work_actual|get_hour = ###}</td>
					<td>{$vo[work_effect_918]|get_hour = ###}</td>
					<td>{:round($vo[work_effect_918]/($work_days['min']-$v[total_leave]),3)*100}%</td>
					<td>{$vo[stu_absent]|get_hour = ###}</td>
					<td>{$vo['remain_overtime']}</td>
					<td>
						<foreach name='leave_ch' item='leo' key='k'>
							<notempty name='vo[$leave_en[$k]]'>{$leo}:{$vo[$leave_en[$k]]|get_hour = ###}</notempty>
						</foreach>
					</td>
				</tr>
				</foreach>
			</table>
			<div class="pagination">{$page}</div>
		</form>
	</div>
	<script src="__PUBLIC__/js/common.js"></script>
	<script>
		$('.print_nodep').click(function(){
			event.preventDefault()
			var _date_s = $('#date_s').val()
			var _date_e = $('#date_e').val()
			var _date_list = date_list(_date_s,_date_e);
			var _date_len = _date_list.length;
			var _data = {
					'name':$('#name').val(),
					'dep_id':$('#dep_id').val(),
					'end':0,
					'code':Math.ceil(Math.random()*100)
					}
			
			
			for (var i in _date_list){
				_data.date_start = _date_list[i].s;
				_data.date_end = _date_list[i].e;
				if (parseInt(i)+1 == _date_len) {
					_data.end = 1;
				}
				var ret = post_request(_data);
				if (!ret) break;
			}
			
		})
		
		function post_request(_data){
			var ret = true;
		 	$.ajax({
				type:'post',
				url:"{:U('print_monthly_no_dep',['print'=>1])}",
				data:{'data':_data},
				success:function(ret){
						console.log(ret.info)
					if (ret.status){
					}else{
						//alert(ret.info);
						ret = false;
					}
				}
			}) 
			
			return ret
		}
		
		//判断是否进行分割日期
		function date_list(start,end){
			var time_info_start = start.split('-');
			var time_info_end = end.split('-');
			var mon_start = parseInt(time_info_start[0]) * 12 + parseInt(time_info_start[1]);
			var mon_end = parseInt(time_info_end[0]) * 12 + parseInt(time_info_end[1]);
			var intval_m = Math.abs(mon_start - mon_end);	//月份差
			
			//天数查
			var time2 = Date.parse(start)/1000;
		    var time1 = Date.parse(end)/1000;
		    var intval_d = ((time1 - time2)/(3600*24));//天数差
		    var date_list = new Array();
		    console.log(intval_d)
		    
		    if (intval_m >=1 && intval_d>= 30){
		    	for(var i=0; i<intval_m;i++){
		    		var dateobj = new Object();
		    		var new_year = parseInt(time_info_start[0])+parseInt(i/12);
		    		var new_month = parseInt(time_info_start[1])+(i%12);
			    	
		    		var new_date = new Date(new_year,new_month,1);        //取当年当月中的第一天   
			    	var new_mon_last_day =  (new Date(new_date.getTime()-1000*60*60*24)).getDate();//获取当月最后一天日期
			    	dateobj.s = new_year+'-'+new_month+'-01';
			    	dateobj.e = new_year+'-'+new_month+'-'+new_mon_last_day ;
		    		date_list[i] = dateobj;
		    	}
		    	var endtime_s = time_info_end[0]+"-"+time_info_end[1]+'-'+"01";
		    	date_list.push({'s':endtime_s,'e':end});
		    	
		    }else{
		    	date_list.push({'s':start,'e':end});
		    }
		    console.log(date_list)
			return date_list;
		}
		
	</script>
</body>
</html>

